Skip to content

Comments

fix(iOS): prevent search bar from reopening keyboard on header button press#3676

Open
just1and0 wants to merge 1 commit intosoftware-mansion:mainfrom
just1and0:fix/ios-search-bar-keyboard-reopen
Open

fix(iOS): prevent search bar from reopening keyboard on header button press#3676
just1and0 wants to merge 1 commit intosoftware-mansion:mainfrom
just1and0:fix/ios-search-bar-keyboard-reopen

Conversation

@just1and0
Copy link

@just1and0 just1and0 commented Feb 22, 2026

Description

Closes #3677.

When a screen has both a headerSearchBarOptions search bar and header buttons (e.g. headerRight), tapping a header button after dismissing the search bar keyboard causes the keyboard to reopen unexpectedly.

Repro steps:

  1. Have a screen with both a search bar and a header right button
  2. Tap the search bar to focus it (keyboard opens)
  3. Dismiss the keyboard (tap Cancel or tap away)
  4. Tap the header right button
  5. Bug: The keyboard opens again instead of just triggering the button action

Minimal reproduction: https://github.com/sbkl/sdk-55-header-right-button-opening-keyboard

Also reported on Expo: expo/expo#43198

Changes

Two fixes in the iOS native code:

  1. RNSScreenStackHeaderConfig.mm: Guard the navitem.searchController assignment to only occur when the value actually changes. Previously, this was unconditionally reassigned on every updateViewController call, which caused UIKit to re-activate the search bar and trigger the keyboard.

  2. RNSSearchBar.mm: In searchBarCancelButtonClicked:, also call resignFirstResponder on the actual _controller.searchBar (the native UISearchBar), not just on self (the RNSSearchBar wrapper). This ensures the search bar fully gives up keyboard focus when cancelled.

Before & after

Before (bug)

Screen.Recording.2026-02-17.at.9.09.11.AM.mov

After focusing and dismissing the search bar, tapping the header menu button reopens the keyboard.

After (fix)

After the fix, tapping the header menu button correctly triggers the menu action without reopening the keyboard.

Test plan

  • Added TestSearchBarKeyboardReopen.tsx in apps/src/tests/issue-tests/
  • Steps to test:
    1. Open the test screen (has a search bar + "Menu" header right button)
    2. Tap the search bar to focus it
    3. Dismiss the keyboard
    4. Tap the "Menu" button in the header
    5. Verify the keyboard does not reopen and the button action fires correctly

Checklist

  • Included code example that can be used to test this change.
  • Updated / created local changelog entries in relevant test files.
  • For visual changes, included screenshots / GIFs / recordings documenting the change.
  • For API changes, updated relevant public types.
  • Ensured that CI passes

… press

When a screen has both a search bar and header buttons, tapping a header
button after dismissing the search bar keyboard causes the keyboard to
reopen unexpectedly. This happens because:

1. updateViewController unconditionally reassigns navitem.searchController
   on every render cycle, causing UIKit to re-activate the search bar.
2. searchBarCancelButtonClicked does not resign first responder on the
   actual UISearchBar, only on the RNSSearchBar wrapper.

This commit guards the searchController assignment to only occur when the
value changes, and ensures the native search bar properly resigns first
responder when cancelled.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug on iOS where tapping a header button after dismissing the search bar keyboard causes the keyboard to reopen unexpectedly. The fix involves preventing UIKit from re-activating the search bar when navigation properties are updated, and ensuring the search bar properly releases first responder status when cancelled.

Changes:

  • Guarded navitem.searchController assignment to prevent UIKit from re-activating the search bar on every React re-render
  • Added explicit resignFirstResponder call on the native UISearchBar when the cancel button is clicked
  • Added test file TestSearchBarKeyboardReopen.tsx to verify the fix

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
ios/RNSScreenStackHeaderConfig.mm Guards searchController assignment to only update when value changes, preventing UIKit from re-activating search bar
ios/RNSSearchBar.mm Adds resignFirstResponder on native UISearchBar in cancel handler to ensure keyboard is fully dismissed
apps/src/tests/issue-tests/TestSearchBarKeyboardReopen.tsx Test case demonstrating the fix with search bar + header button interaction
apps/src/tests/issue-tests/index.ts Exports new test file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

1. Tap the search bar to focus it{'\n'}
2. Dismiss the keyboard (tap Cancel or tap away){'\n'}
3. Tap the "Menu" button in the header{'\n'}
4. Bug: The keyboard opens again instead of just triggering the button
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description in the comment says "4. Bug: The keyboard opens again instead of just triggering the button" but this is describing the bug that was fixed, not the current expected behavior. Since this is a test file documenting the fix, the comment should clarify that this was the previous buggy behavior, or update it to describe the expected behavior after the fix (keyboard should NOT reopen).

Suggested change
4. Bug: The keyboard opens again instead of just triggering the button
4. Expected: The keyboard should remain dismissed and only the button press should be handled (previously, the keyboard would reopen)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iOS: Header button reopens keyboard after search bar is dismissed

1 participant